package algorithm;

public class T00014 {

    public static void main(String[] args) {
        String[] arr = {"aa","a"};
        System.out.println(new Solution().longestCommonPrefix(arr));
    }

static class Solution {
    public String longestCommonPrefix(String[] strs) {
        if(strs == null || strs.length == 0)
            return "";
        char[] rs = strs[0].toCharArray();
        if(rs == null || rs.length == 0)
            return "";
        int j;
        for(j = 0;j < strs[0].length();j ++) {
            char c = strs[0].charAt(j);
            for (int i = 1; i < strs.length; i++) {
                if(strs[i] == null || strs[i].length() == 0 || j >= strs[i].length() || strs[i].charAt(j) != c)
                    return new String(rs, 0, j);
            }
        }
        return strs[0];
    }
}
}
